# -*- coding = utf-8 -*-
# @Time : 2021/12/16 9:10
# @Author : 龙王赘婿_彪少
# @File : yinziwei.py
# @Software: PyCharm

import openpyxl
import re

class YZW:
    def __init__(self):
        self.loadfile()
        self.dealfile()
        self.savefile()

    def loadfile(self):
        # 读取报表
        self.wb = openpyxl.load_workbook("demo_excel.xlsx")
        # self.wb = openpyxl.Workbook()

        # 打印表单名字
        print(self.wb.sheetnames)

        # 获取表单
        self.ws = self.wb['Sheet1']

    def dealfile(self):
        # 行遍历
        for row in self.ws.rows:
            # 每行的第一格
            cell1 = row[0]
            # 每行的第四格
            cell2 = self.ws.cell(cell1.row, 4)
            # 正则表达式赋值
            cell2.value = re.findall("(.+?)-11A-", cell1.value)[0]
            # print(cell1.value)
            # print(cell2.value)

    def savefile(self):
        self.wb.save("demo_excel2.xlsx")

if __name__ == '__main__':
    print("begin")
    yzw = YZW()
